﻿using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Text;
using System.Threading;

namespace FunAndActionInterface
{

    public interface IContext 
    {

        /// <summary>
        /// Stash of items that can carry stuff for later use in the transaction
        /// </summary>
        System.Collections.Concurrent.ConcurrentDictionary<string, object> Items { get; }
    }
    class Class1
    {
        static readonly AsyncLocal<IContext> AsyncLocalTxContext = new AsyncLocal<IContext>();

        /// <summary>
        /// Gets the default set function (which is using <see cref="System.Threading.AsyncLocal{T}"/> to do its thing)
        /// </summary>
        public static readonly Action<IContext> DefaultSetter = context => AsyncLocalTxContext.Value = context;

        /// <summary>
        /// Gets the default set function (which is using <see cref="System.Threading.AsyncLocal{T}"/> to do its thing)
        /// </summary>
        public static readonly Func<IContext> DefaultGetter = () => AsyncLocalTxContext.Value;


        static Action<IContext> _setCurrent = DefaultSetter;
        static Func<IContext> _getCurrent = DefaultGetter;


        public static IContext Current => _getCurrent();
    }
}
